﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net;

public class Mail
{
    public static void Send(String from, String to, String subject, String body)
    {
        Send(from, to, "", "", subject, body, "");
    }

    public static void Send(String from, String to, String cc, String bcc, String subject, String body, String attachments)
    {
        var message = new MailMessage();
        message.IsBodyHtml = true;
        message.From = new MailAddress(from);
        message.To.Add(new MailAddress(to));
        message.Subject = subject;
        message.Body = body;
        message.ReplyToList.Add(from);
        if (cc.Length > 0)
        {
            message.CC.Add(cc);
        }
        if (bcc.Length > 0)
        {
            message.Bcc.Add(bcc);
        }
        if (attachments.Length > 0)
        {
            String[] fileNames = attachments.Split(';', ',');
            foreach (var fileName in fileNames)
            {
                message.Attachments.Add(new Attachment(fileName));
            }
        }

        // Kết nối GMail
        var client = new SmtpClient("smtp.gmail.com", 25)
        {
            Credentials = new NetworkCredential("truongnguyen3168@gmail.com", "anhtruong@"),
            EnableSsl = true
        };
        // gởi mail
        client.Send(message);
    }
}